/**
 * @Title: involve.js
 * @Description: TODO
 * Copyright: Copyright (c) 2014 
 * Company:中国平安
 *
 * @Project HIMS-FWA
 * @author ex-xieqi001
 * @date 2014年11月17日 下午11:48:10
 * @version V1.0
 */
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.directives');
	app.directive('fwaInvolve', ['BaseURL',function(baseUrl){
		
		function ctrler($scope, $element, $attrs, $transclude) {
			
			
			$scope.countType = $attrs.countType || false;
			
			//监听是否可以点击总数量
			$scope.$watchCollection($attrs.countType,function(v){
				$scope.countType = v;
			});
			
			//监听是否显示操作
			$scope.$watchCollection($attrs.medicalTypeShow,function(v){
				if (v) {
					//新增医疗机构
					$scope.medicalAddShow = v.add || false;
					//医疗机构 计分
					$scope.medicalDeductionShow = v.deduction || false;
					//医疗机构删除
					$scope.medicalDelShow = v.del || false;
				}
				else {
					//新增医疗机构
					$scope.medicalAddShow = false;
					//医疗机构 计分
					$scope.medicalDeductionShow =  false;
					//医疗机构删除
					$scope.medicalDelShow =  false;
				}
				
			});
			
			//监听是否显示操作
			$scope.$watchCollection($attrs.staffTypeShow,function(v){
				if (v) {
					//新增 医护人员
					$scope.staffAddShow = v.add || false;
					//医护人员 计分
					$scope.staffDeductionShow = v.deduction || false;
					//医护人员 删除
					$scope.staffDelShow = v.del || false;
				}
				else {
					//新增 医护人员
					$scope.staffAddShow = false;
					//医护人员 计分
					$scope.staffDeductionShow =  false;
					//医护人员 删除
					$scope.staffDelShow =  false;
				}
				
			});
			
			//监听是否显示操作
			$scope.$watchCollection($attrs.insuranceTypeShow,function(v){
				if (v) {
					//新增 参保人
					$scope.insuranceAddShow = v.add || false;
					//参保人 计分
					$scope.insuranceDeductionShow = v.deduction || false;
					//参保人 删除
					$scope.insuranceDelShow = v.del || false;
				}
				else {
					//新增 参保人
					$scope.insuranceAddShow = false;
					//参保人 计分
					$scope.insuranceDeductionShow =  false;
					//参保人 删除
					$scope.insuranceDelShow = false;
				}
				
			});
			
			//监听医疗机构数据变化
			$scope.$watchCollection($attrs.medical,function(v){
				 if (v) {
					 $scope.medicalData = v ;
					 $scope.medicalCount = v.length;
				 }
				 else {
					 $scope.medicalData = [] ;
					 $scope.medicalCount = 0;
				 }
			});

			//监听医务人员数据变化
			$scope.$watchCollection($attrs.staff,function(v){
				if (v) {
					$scope.staffData = v;
					$scope.staffCount = v.length;
				}
				else {
					$scope.staffData = [];
					$scope.staffCount  = 0;
				}
			});
			
			//监听参保人员数据变化
			$scope.$watchCollection($attrs.insurance,function(v){
				if (v) {
					$scope.insuranceData = v;
					$scope.insuranceCount = v.length;
				}
				else {
					$scope.insuranceData = [];
					$scope.insuranceCount = 0;
				}
				
			});
			
			//隐藏扣分以及删除按钮
			$scope.mouseoutShow = function(data){
				data.show = false;
			}
			
	        //显示扣分以及删除按钮
			$scope.mouseoverShow = function(data){
				data.show = true;
			}
			
			//点击医疗机构总数量事件
			$scope.medicalCountClick = function() {
				$scope.$emit('fwaInvolve.medicalCountClick');
			}
			
			//点击医务人员总数量事件
			$scope.staffCountClick = function() {
				$scope.$emit('fwaInvolve.staffCountClick');
			}
			
			//点击参保人总数量事件
			$scope.insuranceCountClick = function() {
				$scope.$emit('fwaInvolve.insuranceCountClick');
			}
			//新增医疗机构 事件
			$scope.medicalAdd = function() {
				$scope.$emit('fwaInvolve.medicalAdd');
			}
			//新增医务人员 事件
			$scope.staffAdd = function() {
				$scope.$emit('fwaInvolve.staffAdd');
			}
			
			//新增参保人 事件
			$scope.insuranceAdd = function() {
				$scope.$emit('fwaInvolve.insuranceAdd');
			}
			
			//医疗机构扣分事件
			$scope.medicalDeduction = function(data){
				$scope.$emit('fwaInvolve.medicalDeduction',data);
			}
			
			//医务人员扣分事件
			$scope.staffDeduction = function(data){
				$scope.$emit('fwaInvolve.staffDeduction',data);
			}
			
			//参保人扣分事件
			$scope.insuranceDeduction = function(data){
				$scope.$emit('fwaInvolve.insuranceDeduction',data);
			}
			
			//医疗机构删除事件
			$scope.medicalDel = function(data) {
				angular.forEach($scope.medicalData,function(medical,index){
					if (data ===  medical) {
						$scope.medicalData.splice(index,1);
					}
				});
				$scope.$emit('fwaInvolve.medicalDel',data);
			}
			
			//医务人员删除事件
			$scope.staffDel = function(data) {
				/*angular.forEach($scope.staffData,function(staff,index){
					if (data ===  staff) {
						$scope.staffData.splice(index,1);
					}
				});*/
				$scope.$emit('fwaInvolve.staffDel',data);
			}
			
			//参保人删除事件
			$scope.insuranceDel = function(data) {
				/*angular.forEach($scope.insuranceData,function(insurance,index){
					if (data ===  insurance) {
						$scope.insuranceData.splice(index,1);
					}
				});*/
				$scope.$emit('fwaInvolve.insuranceDel',data);
			}
		}
		
		return {
			restrict: 'E',
			scope:true,
			replace:true,
			templateUrl:baseUrl + 'views/hcpms/common/directives/involve.html',
			controller:ctrler
		};
		
	}]);
	
})();